package Threading;

public class demo6 {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
           while(!Thread.currentThread().isInterrupted()){
               //Thread.interruted()这是一个静态方法 Thread.currentThread().isInterrupted()这是一个实例方法，
               // 其中currentThread能够获取到当前线程的实例，而isInterrupted()就是判断标志位的
               System.out.println("hello thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.getStackTrace();
                   System.out.println("这是收尾工作");
                   break;
               }
           }
        });
        t.start();

        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.getStackTrace();
        }
        t.interrupt();
    }
}
